package de.hs_rm.mmk.group_talk.network_communication;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class Communication {

	 public int serverPort = 444;	 
	 private Socket serverSocket;
	 private PrintWriter out;
	 private BufferedReader in;	 
	 private static Communication instance;
	 
	 private Communication(String address, int port) {
		 
		 try {
			 
			this.serverPort = port; 
			this.serverSocket = new Socket(address, serverPort);
			this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(this.serverSocket.getOutputStream())), true);
			this.in = new BufferedReader(new InputStreamReader(this.serverSocket.getInputStream()));	
				
			} catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		 
		 		 
	 }
	 
	 public static Communication getInstance(String address, int port){
		 if (instance == null) {
			 instance = new Communication(address, port);
		 }
		 return instance;
	 }
	 
	 public void createNewGroup(String groupName) {
		 
		 this.out.println("CNG");
		 this.out.println(groupName);
		 
	 }
	 
	 public void joinGroup(String groupName)  {
		 
	 }
	 
	 public void getGroupNames() {
		 
	 }
	 
	 public String[] getUserNames(String groupName){
		 String[] users = new String[]{ "User1", "User2", "User3", "User4" };
		 return users;
	 }
	 
	 public int getNumberOfPlayers(String groupName){
		 int players = 0;
		 return players;
	 }
	 
	 public boolean getSpeechState(String userName){
		 
		 return true;
	 }
	 
	 public void setSpeechStatToTrue(String username){
		 
	 }
	 
	 public boolean isAudioData(){
		 
		 return true;
	 }
	 
	 
}
